home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / Tools / Dev / SpeakFreely_Src / gsm / src / long_term.c < prev    next >
C/C++ Source or Header  |  2000-05-27  |  15KB  |  611 lines

  1. /*
  2.  * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
  3.  * Universitaet Berlin.  See the accompanying file "COPYRIGHT" for
  4.  * details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
  5.  */
  6.  
  7. /* $Header: /home/kbs/jutta/src/gsm/gsm-1.0/src/RCS/long_term.c,v 1.1 1992/10/28 00:15:50 jutta Exp $ */
  8.  
  9. #include <stdio.h>
  10. #include <assert.h>
  11.  
  12. #include "private.h"
  13.  
  14. #include "gsm.h"
  15. #include "proto.h"
  16.  
  17.  
  18. #ifdef    USE_TABLE_MUL
  19.  
  20. unsigned int umul_table[ 513 ][ 256 ];
  21.  
  22. init_umul_table()
  23. {
  24.     int    i, j;
  25.     int    n;
  26.     unsigned int     * p = &umul_table[0][0];
  27.  
  28.     for (i = 0; i < 513; i++) {
  29.         n = 0;
  30.         for (j = 0; j < 256; j++) {
  31.             *p++ = n;
  32.             n += i;
  33.         }
  34.     }
  35. }
  36.  
  37. # define umul(x9, x15)    \
  38.     ((int)(umul_table[x9][x15 & 0x0FF] + (umul_table[x9][ x15 >> 8 ] << 8)))
  39.  
  40. # define table_mul(a, b)    \
  41.     ( (a < 0)  ? ((b < 0) ? umul(-a, -b) : -umul(-a, b))    \
  42.              : ((b < 0) ? -umul(a, -b) :  umul(a, b)))
  43.  
  44. #endif /* USE_TABLE_MUL */
  45.  
  46.  
  47.  
  48. /*
  49.  *  4.2.11 .. 4.2.12 LONG TERM PREDICTOR (LTP) SECTION
  50.  */
  51.  
  52.  
  53. /*
  54.  * This procedure computes the LTP gain (bc) and the LTP lag (Nc)
  55.  * for the long term analysis filter.   This is done by calculating a
  56.  * maximum of the cross-correlation function between the current
  57.  * sub-segment short term residual signal d[0..39] (output of
  58.  * the short term analysis filter; for simplification the index
  59.  * of this array begins at 0 and ends at 39 for each sub-segment of the
  60.  * RPE-LTP analysis) and the previous reconstructed short term
  61.  * residual signal dp[ -120 .. -1 ].  A dynamic scaling must be
  62.  * performed to avoid overflow.
  63.  */
  64.  
  65.  /* This procedure exists in four versions.  First, the two integer
  66.   * versions with or without table-multiplication (as one function);
  67.   * then, the two floating point versions (as another function), with
  68.   * or without scaling.
  69.   */
  70.  
  71. #ifndef  USE_FLOAT_MUL
  72.  
  73. static void Calculation_of_the_LTP_parameters P4((d,dp,bc_out,Nc_out),
  74.     register word    * d,        /* [0..39]    IN    */
  75.     register word    * dp,        /* [-120..-1]    IN    */
  76.     word        * bc_out,    /*         OUT    */
  77.     word        * Nc_out    /*         OUT    */
  78. )
  79. {
  80.     register ulongword utmp;    /* for L_ADD */
  81.  
  82.     register int      k, lambda;
  83.     word        Nc, bc;
  84.     word        wt[40];
  85.  
  86.     longword    L_max, L_power;
  87.     word        R, S, dmax, scal;
  88.     register word    temp;
  89.  
  90.     /*  Search of the optimum scaling of d[0..39].
  91.      */
  92.     dmax = 0;
  93.  
  94.     for (k = 0; k <= 39; k++) {
  95.         temp = d[k];
  96.         temp = GSM_ABS( temp );
  97.         if (temp > dmax) dmax = temp;
  98.     }
  99.  
  100.     temp = 0;
  101.     if (dmax == 0) scal = 0;
  102.     else {
  103.         assert(dmax > 0);
  104.         temp = gsm_norm( dmax << 16 );
  105.     }
  106.  
  107.     if (temp > 6) scal = 0;
  108.     else scal = 6 - temp;
  109.  
  110.     assert(scal >= 0);
  111.  
  112.     /*  Initialization of a working array wt
  113.      */
  114.  
  115.     for (k = 0; k <= 39; k++) wt[k] = SASR( d[k], scal );
  116.  
  117.     /* Search for the maximum cross-correlation and coding of the LTP lag
  118.      */
  119.     L_max = 0;
  120.     Nc    = 40;    /* index for the maximum cross-correlation */
  121.  
  122.     for (lambda = 40; lambda <= 120; lambda++) {
  123.  
  124. # undef STEP
  125. # ifdef USE_TABLE_MUL
  126. #        define STEP(k) (table_mul(wt[k], dp[k - lambda]))
  127. # else
  128. #        define STEP(k) (wt[k] * dp[k - lambda])
  129. # endif
  130.  
  131.         register longword L_result;
  132.  
  133.         L_result  = STEP(0)  ; L_result += STEP(1) ;
  134.         L_result += STEP(2)  ; L_result += STEP(3) ;
  135.         L_result += STEP(4)  ; L_result += STEP(5)  ;
  136.         L_result += STEP(6)  ; L_result += STEP(7)  ;
  137.         L_result += STEP(8)  ; L_result += STEP(9)  ;
  138.         L_result += STEP(10) ; L_result += STEP(11) ;
  139.         L_result += STEP(12) ; L_result += STEP(13) ;
  140.         L_result += STEP(14) ; L_result += STEP(15) ;
  141.         L_result += STEP(16) ; L_result += STEP(17) ;
  142.         L_result += STEP(18) ; L_result += STEP(19) ;
  143.         L_result += STEP(20) ; L_result += STEP(21) ;
  144.         L_result += STEP(22) ; L_result += STEP(23) ;
  145.         L_result += STEP(24) ; L_result += STEP(25) ;
  146.         L_result += STEP(26) ; L_result += STEP(27) ;
  147.         L_result += STEP(28) ; L_result += STEP(29) ;
  148.         L_result += STEP(30) ; L_result += STEP(31) ;
  149.         L_result += STEP(32) ; L_result += STEP(33) ;
  150.         L_result += STEP(34) ; L_result += STEP(35) ;
  151.         L_result += STEP(36) ; L_result += STEP(37) ;
  152.         L_result += STEP(38) ; L_result += STEP(39) ;
  153.  
  154.         if (L_result > L_max) {
  155.  
  156.             Nc    = lambda;
  157.             L_max = L_result;
  158.         }
  159.     }
  160.  
  161.     *Nc_out = Nc;
  162.  
  163.     L_max <<= 1;
  164.  
  165.     /*  Rescaling of L_max
  166.      */
  167.     assert(scal <= 100 && scal >=  -100);
  168.     L_max = L_max >> (6 - scal);    /* sub(6, scal) */
  169.  
  170.     assert( Nc <= 120 && Nc >= 40);
  171.  
  172.     /*   Compute the power of the reconstructed short term residual
  173.      *   signal dp[..]
  174.      */
  175.     L_power = 0;
  176.     for (k = 0; k <= 39; k++) {
  177.  
  178.         register longword L_temp;
  179.  
  180.         L_temp   = SASR( dp[k - Nc], 3 );
  181.         L_power += L_temp * L_temp;
  182.     }
  183.     L_power <<= 1;    /* from L_MULT */
  184.  
  185.     /*  Normalization of L_max and L_power
  186.      */
  187.  
  188.     if (L_max <= 0)  {
  189.         *bc_out = 0;
  190.         return;
  191.     }
  192.     if (L_max >= L_power) {
  193.         *bc_out = 3;
  194.         return;
  195.     }
  196.  
  197.     temp = gsm_norm( L_power );
  198.  
  199.     R = SASR( L_max   << temp, 16 );
  200.     S = SASR( L_power << temp, 16 );
  201.  
  202.     /*  Coding of the LTP gain
  203.      */
  204.  
  205.     /*  Table 4.3a must be used to obtain the level DLB[i] for the
  206.      *  quantization of the LTP gain b to get the coded version bc.
  207.      */
  208.     for (bc = 0; bc <= 2; bc++) if (R <= gsm_mult(S, gsm_DLB[bc])) break;
  209.     *bc_out = bc;
  210. }
  211.  
  212. #else    /* USE_FLOAT_MUL */
  213.  
  214. static void Calculation_of_the_LTP_parameters P4((d,dp,bc_out,Nc_out),
  215.     register word    * d,        /* [0..39]    IN    */
  216.     register word    * dp,        /* [-120..-1]    IN    */
  217.     word        * bc_out,    /*         OUT    */
  218.     word        * Nc_out    /*         OUT    */
  219. )
  220. {
  221.     register ulongword utmp;    /* for L_ADD */
  222.  
  223.     register int      k, lambda;
  224.     word        Nc, bc;
  225.  
  226.     float        wt_float[40];
  227.     float        dp_float_base[120], * dp_float = dp_float_base + 120;
  228.  
  229.     longword    L_max, L_power;
  230.     word        R, S, dmax, scal;
  231.     register word    temp;
  232.  
  233.     /*  Search of the optimum scaling of d[0..39].
  234.      */
  235.     dmax = 0;
  236.  
  237.     for (k = 0; k <= 39; k++) {
  238.         temp = d[k];
  239.         temp = GSM_ABS( temp );
  240.         if (temp > dmax) dmax = temp;
  241.     }
  242.  
  243.     temp = 0;
  244.     if (dmax == 0) scal = 0;
  245.     else {
  246.         assert(dmax > 0);
  247.         temp = gsm_norm( dmax << 16 );
  248.     }
  249.  
  250.     if (temp > 6) scal = 0;
  251.     else scal = 6 - temp;
  252.  
  253.     assert(scal >= 0);
  254.  
  255.     /*  Initialization of a working array wt
  256.      */
  257.  
  258.     for (k =    0; k < 40; k++) wt_float[k] =  SASR( d[k], scal );
  259.     for (k = -120; k <  0; k++) dp_float[k] =  dp[k];
  260.  
  261.     /* Search for the maximum cross-correlation and coding of the LTP lag
  262.      */
  263.     L_max = 0;
  264.     Nc    = 40;    /* index for the maximum cross-correlation */
  265.  
  266.     for (lambda = 40; lambda <= 120; lambda += 9) {
  267.  
  268.         /*  Calculate L_result for l = lambda .. lambda + 9.
  269.          */
  270.         register float *lp = dp_float - lambda;
  271.  
  272.         register float    W;
  273.         register float    a = lp[-8], b = lp[-7], c = lp[-6],
  274.                 d = lp[-5], e = lp[-4], f = lp[-3],
  275.                 g = lp[-2], h = lp[-1];
  276.         register float  E; 
  277.         register float  S0 = 0, S1 = 0, S2 = 0, S3 = 0, S4 = 0,
  278.                 S5 = 0, S6 = 0, S7 = 0, S8 = 0;
  279.  
  280. #        undef STEP
  281. #        define    STEP(K, a, b, c, d, e, f, g, h) \
  282.             W = wt_float[K];        \
  283.             E = W * a; S8 += E;        \
  284.             E = W * b; S7 += E;        \
  285.             E = W * c; S6 += E;        \
  286.             E = W * d; S5 += E;        \
  287.             E = W * e; S4 += E;        \
  288.             E = W * f; S3 += E;        \
  289.             E = W * g; S2 += E;        \
  290.             E = W * h; S1 += E;        \
  291.             a  = lp[K];            \
  292.             E = W * a; S0 += E
  293.  
  294. #        define    STEP_A(K)    STEP(K, a, b, c, d, e, f, g, h)
  295. #        define    STEP_B(K)    STEP(K, b, c, d, e, f, g, h, a)
  296. #        define    STEP_C(K)    STEP(K, c, d, e, f, g, h, a, b)
  297. #        define    STEP_D(K)    STEP(K, d, e, f, g, h, a, b, c)
  298. #        define    STEP_E(K)    STEP(K, e, f, g, h, a, b, c, d)
  299. #        define    STEP_F(K)    STEP(K, f, g, h, a, b, c, d, e)
  300. #        define    STEP_G(K)    STEP(K, g, h, a, b, c, d, e, f)
  301. #        define    STEP_H(K)    STEP(K, h, a, b, c, d, e, f, g)
  302.  
  303.         STEP_A( 0); STEP_B( 1); STEP_C( 2); STEP_D( 3);
  304.         STEP_E( 4); STEP_F( 5); STEP_G( 6); STEP_H( 7);
  305.  
  306.         STEP_A( 8); STEP_B( 9); STEP_C(10); STEP_D(11);
  307.         STEP_E(12); STEP_F(13); STEP_G(14); STEP_H(15);
  308.  
  309.         STEP_A(16); STEP_B(17); STEP_C(18); STEP_D(19);
  310.         STEP_E(20); STEP_F(21); STEP_G(22); STEP_H(23);
  311.  
  312.         STEP_A(24); STEP_B(25); STEP_C(26); STEP_D(27);
  313.         STEP_E(28); STEP_F(29); STEP_G(30); STEP_H(31);
  314.  
  315.         STEP_A(32); STEP_B(33); STEP_C(34); STEP_D(35);
  316.         STEP_E(36); STEP_F(37); STEP_G(38); STEP_H(39);
  317.  
  318.         if (S0 > L_max) { L_max = S0; Nc = lambda;     }
  319.         if (S1 > L_max) { L_max = S1; Nc = lambda + 1; }
  320.         if (S2 > L_max) { L_max = S2; Nc = lambda + 2; }
  321.         if (S3 > L_max) { L_max = S3; Nc = lambda + 3; }
  322.         if (S4 > L_max) { L_max = S4; Nc = lambda + 4; }
  323.         if (S5 > L_max) { L_max = S5; Nc = lambda + 5; }
  324.         if (S6 > L_max) { L_max = S6; Nc = lambda + 6; }
  325.         if (S7 > L_max) { L_max = S7; Nc = lambda + 7; }
  326.         if (S8 > L_max) { L_max = S8; Nc = lambda + 8; }
  327.     }
  328.     *Nc_out = Nc;
  329.  
  330.     L_max <<= 1;
  331.  
  332.     /*  Rescaling of L_max
  333.      */
  334.     assert(scal <= 100 && scal >=  -100);
  335.     L_max = L_max >> (6 - scal);    /* sub(6, scal) */
  336.  
  337.     assert( Nc <= 120 && Nc >= 40);
  338.  
  339.     /*   Compute the power of the reconstructed short term residual
  340.      *   signal dp[..]
  341.      */
  342.     L_power = 0;
  343.     for (k = 0; k <= 39; k++) {
  344.  
  345.         register longword L_temp;
  346.  
  347.         L_temp   = SASR( dp[k - Nc], 3 );
  348.         L_power += L_temp * L_temp;
  349.     }
  350.     L_power <<= 1;    /* from L_MULT */
  351.  
  352.     /*  Normalization of L_max and L_power
  353.      */
  354.  
  355.     if (L_max <= 0)  {
  356.         *bc_out = 0;
  357.         return;
  358.     }
  359.     if (L_max >= L_power) {
  360.         *bc_out = 3;
  361.         return;
  362.     }
  363.  
  364.     temp = gsm_norm( L_power );
  365.  
  366.     R = SASR( L_max   << temp, 16 );
  367.     S = SASR( L_power << temp, 16 );
  368.  
  369.     /*  Coding of the LTP gain
  370.      */
  371.  
  372.     /*  Table 4.3a must be used to obtain the level DLB[i] for the
  373.      *  quantization of the LTP gain b to get the coded version bc.
  374.      */
  375.     for (bc = 0; bc <= 2; bc++) if (R <= gsm_mult(S, gsm_DLB[bc])) break;
  376.     *bc_out = bc;
  377. }
  378.  
  379. #ifdef    FAST
  380.  
  381. static void Fast_Calculation_of_the_LTP_parameters P4((d,dp,bc_out,Nc_out),
  382.     register word    * d,        /* [0..39]    IN    */
  383.     register word    * dp,        /* [-120..-1]    IN    */
  384.     word        * bc_out,    /*         OUT    */
  385.     word        * Nc_out    /*         OUT    */
  386. )
  387. {
  388.     register ulongword utmp;    /* for L_ADD */
  389.  
  390.     register int      k, lambda;
  391.     word        Nc, bc;
  392.  
  393.     float        wt_float[40];
  394.     float        dp_float_base[120], * dp_float = dp_float_base + 120;
  395.  
  396.     register float    L_max, L_power;
  397.  
  398.     for (k = 0; k < 40; ++k) wt_float[k] = (float)d[k];
  399.     for (k = -120; k <= 0; ++k) dp_float[k] = (float)dp[k];
  400.  
  401.     /* Search for the maximum cross-correlation and coding of the LTP lag
  402.      */
  403.     L_max = 0;
  404.     Nc    = 40;    /* index for the maximum cross-correlation */
  405.  
  406.     for (lambda = 40; lambda <= 120; lambda += 9) {
  407.  
  408.         /*  Calculate L_result for l = lambda .. lambda + 9.
  409.          */
  410.         register float *lp = dp_float - lambda;
  411.  
  412.         register float    W;
  413.         register float    a = lp[-8], b = lp[-7], c = lp[-6],
  414.                 d = lp[-5], e = lp[-4], f = lp[-3],
  415.                 g = lp[-2], h = lp[-1];
  416.         register float  E; 
  417.         register float  S0 = 0, S1 = 0, S2 = 0, S3 = 0, S4 = 0,
  418.                 S5 = 0, S6 = 0, S7 = 0, S8 = 0;
  419.  
  420. #        undef STEP
  421. #        define    STEP(K, a, b, c, d, e, f, g, h) \
  422.             W = wt_float[K];        \
  423.             E = W * a; S8 += E;        \
  424.             E = W * b; S7 += E;        \
  425.             E = W * c; S6 += E;        \
  426.             E = W * d; S5 += E;        \
  427.             E = W * e; S4 += E;        \
  428.             E = W * f; S3 += E;        \
  429.             E = W * g; S2 += E;        \
  430.             E = W * h; S1 += E;        \
  431.             a  = lp[K];            \
  432.             E = W * a; S0 += E
  433.  
  434. #        define    STEP_A(K)    STEP(K, a, b, c, d, e, f, g, h)
  435. #        define    STEP_B(K)    STEP(K, b, c, d, e, f, g, h, a)
  436. #        define    STEP_C(K)    STEP(K, c, d, e, f, g, h, a, b)
  437. #        define    STEP_D(K)    STEP(K, d, e, f, g, h, a, b, c)
  438. #        define    STEP_E(K)    STEP(K, e, f, g, h, a, b, c, d)
  439. #        define    STEP_F(K)    STEP(K, f, g, h, a, b, c, d, e)
  440. #        define    STEP_G(K)    STEP(K, g, h, a, b, c, d, e, f)
  441. #        define    STEP_H(K)    STEP(K, h, a, b, c, d, e, f, g)
  442.  
  443.         STEP_A( 0); STEP_B( 1); STEP_C( 2); STEP_D( 3);
  444.         STEP_E( 4); STEP_F( 5); STEP_G( 6); STEP_H( 7);
  445.  
  446.         STEP_A( 8); STEP_B( 9); STEP_C(10); STEP_D(11);
  447.         STEP_E(12); STEP_F(13); STEP_G(14); STEP_H(15);
  448.  
  449.         STEP_A(16); STEP_B(17); STEP_C(18); STEP_D(19);
  450.         STEP_E(20); STEP_F(21); STEP_G(22); STEP_H(23);
  451.  
  452.         STEP_A(24); STEP_B(25); STEP_C(26); STEP_D(27);
  453.         STEP_E(28); STEP_F(29); STEP_G(30); STEP_H(31);
  454.  
  455.         STEP_A(32); STEP_B(33); STEP_C(34); STEP_D(35);
  456.         STEP_E(36); STEP_F(37); STEP_G(38); STEP_H(39);
  457.  
  458.         if (S0 > L_max) { L_max = S0; Nc = lambda;     }
  459.         if (S1 > L_max) { L_max = S1; Nc = lambda + 1; }
  460.         if (S2 > L_max) { L_max = S2; Nc = lambda + 2; }
  461.         if (S3 > L_max) { L_max = S3; Nc = lambda + 3; }
  462.         if (S4 > L_max) { L_max = S4; Nc = lambda + 4; }
  463.         if (S5 > L_max) { L_max = S5; Nc = lambda + 5; }
  464.         if (S6 > L_max) { L_max = S6; Nc = lambda + 6; }
  465.         if (S7 > L_max) { L_max = S7; Nc = lambda + 7; }
  466.         if (S8 > L_max) { L_max = S8; Nc = lambda + 8; }
  467.     }
  468.     *Nc_out = Nc;
  469.  
  470.     if (L_max <= 0.)  {
  471.         *bc_out = 0;
  472.         return;
  473.     }
  474.  
  475.     /*  Compute the power of the reconstructed short term residual
  476.      *  signal dp[..]
  477.      */
  478.     dp_float -= Nc;
  479.     L_power = 0;
  480.     for (k = 0; k < 40; ++k) {
  481.         register float f = dp_float[k];
  482.         L_power += f * f;
  483.     }
  484.  
  485.     if (L_max >= L_power) {
  486.         *bc_out = 3;
  487.         return;
  488.     }
  489.  
  490.     /*  Coding of the LTP gain
  491.      *  Table 4.3a must be used to obtain the level DLB[i] for the
  492.      *  quantization of the LTP gain b to get the coded version bc.
  493.      */
  494.     lambda = L_max / L_power * 32768.;
  495.     for (bc = 0; bc <= 2; ++bc) if (lambda <= gsm_DLB[bc]) break;
  496.     *bc_out = bc;
  497. }
  498.  
  499. #endif    /* FAST      */
  500. #endif    /* USE_FLOAT_MUL */
  501.  
  502.  
  503. /* 4.2.12 */
  504.  
  505. static void Long_term_analysis_filtering P6((bc,Nc,dp,d,dpp,e),
  506.     word        bc,    /*                     IN  */
  507.     word        Nc,    /*                     IN  */
  508.     register word    * dp,    /* previous d    [-120..-1]        IN  */
  509.     register word    * d,    /* d        [0..39]            IN  */
  510.     register word    * dpp,    /* estimate    [0..39]            OUT */
  511.     register word    * e    /* long term res. signal [0..39]    OUT */
  512. )
  513. /*
  514.  *  In this part, we have to decode the bc parameter to compute
  515.  *  the samples of the estimate dpp[0..39].  The decoding of bc needs the
  516.  *  use of table 4.3b.  The long term residual signal e[0..39]
  517.  *  is then calculated to be fed to the RPE encoding section.
  518.  */
  519. {
  520.     register word     bp;
  521.     register int      k;
  522.     register longword ltmp;
  523.  
  524. #    undef STEP
  525. #    define STEP(BP)                    \
  526.     for (k = 0; k <= 39; k++) {            \
  527.         dpp[k]  = GSM_MULT_R( BP, dp[k - Nc]);    \
  528.         e[k]    = GSM_SUB( d[k], dpp[k] );    \
  529.     }
  530.  
  531.     switch (bc) {
  532.     case 0:    STEP(  3277 ); break;
  533.     case 1:    STEP( 11469 ); break;
  534.     case 2: STEP( 21299 ); break;
  535.     case 3: STEP( 32767 ); break; 
  536.     }
  537. }
  538.  
  539. void Gsm_Long_Term_Predictor P7((S,d,dp,e,dpp,Nc,bc),     /* 4x for 160 samples */
  540.  
  541.     struct gsm_state    * S,
  542.  
  543.     word    * d,    /* [0..39]   residual signal    IN    */
  544.     word    * dp,    /* [-120..-1] d'        IN    */
  545.  
  546.     word    * e,    /* [0..39]             OUT    */
  547.     word    * dpp,    /* [0..39]             OUT    */
  548.     word    * Nc,    /* correlation lag        OUT    */
  549.     word    * bc    /* gain factor            OUT    */
  550. )
  551. {
  552.     assert( d  ); assert( dp ); assert( e  );
  553.     assert( dpp); assert( Nc ); assert( bc );
  554.  
  555. #if defined(FAST) && defined(USE_FLOAT_MUL)
  556.     if (S->fast) 
  557.         Fast_Calculation_of_the_LTP_parameters( d, dp, bc, Nc );
  558.     else 
  559. #endif
  560.         Calculation_of_the_LTP_parameters( d, dp, bc, Nc );
  561.  
  562.     Long_term_analysis_filtering( *bc, *Nc, dp, d, dpp, e );
  563. }
  564.  
  565. /* 4.3.2 */
  566. void Gsm_Long_Term_Synthesis_Filtering P5((S,Ncr,bcr,erp,drp),
  567.     struct gsm_state    * S,
  568.  
  569.     word            Ncr,
  570.     word            bcr,
  571.     register word        * erp,        /* [0..39]          IN */
  572.     register word        * drp        /* [-120..-1] IN, [0..40] OUT */
  573. )
  574. /*
  575.  *  This procedure uses the bcr and Ncr parameter to realize the
  576.  *  long term synthesis filtering.  The decoding of bcr needs
  577.  *  table 4.3b.
  578.  */
  579. {
  580.     register longword    ltmp;    /* for ADD */
  581.     register int         k;
  582.     word            brp, drpp, Nr;
  583.  
  584.     /*  Check the limits of Nr.
  585.      */
  586.     Nr = Ncr < 40 || Ncr > 120 ? S->nrp : Ncr;
  587.     S->nrp = Nr;
  588.     assert(Nr >= 40 && Nr <= 120);
  589.  
  590.     /*  Decoding of the LTP gain bcr
  591.      */
  592.     brp = gsm_QLB[ bcr ];
  593.  
  594.     /*  Computation of the reconstructed short term residual 
  595.      *  signal drp[0..39]
  596.      */
  597.     assert(brp != MIN_WORD);
  598.  
  599.     for (k = 0; k <= 39; k++) {
  600.         drpp   = GSM_MULT_R( brp, drp[ k - Nr ] );
  601.         drp[k] = GSM_ADD( erp[k], drpp );
  602.     }
  603.  
  604.     /*
  605.      *  Update of the reconstructed short term residual signal
  606.      *  drp[ -1..-120 ]
  607.      */
  608.  
  609.     for (k = 0; k <= 119; k++) drp[ -120 + k ] = drp[ -80 + k ];
  610. }
  611.